﻿using System.Collections.Generic;
using System.Windows.Controls;

namespace TechNewLogic.GraphIT.Printing
{
	/// <summary>
	/// Interaction logic for PrintLayouter.xaml
	/// </summary>
	partial class PrintLayouter
	{
		private readonly List<ContentControl> _holders = new List<ContentControl>();

		public PrintLayouter(object mainContent, IEnumerable<PrintContent> additionalPrintContent)
		{
			InitializeComponent();

			mainPrintContentHolder.Content = mainContent;

			foreach (var it in additionalPrintContent)
				AddAdditionalContent(it);
		}

		private void AddAdditionalContent(PrintContent content)
		{
			var holder = new ContentControl { Content = content.Visual };
			holder.SetValue(DockPanel.DockProperty, content.Position);
			dockPanel.Children.Insert(0, holder);
			_holders.Add(holder);
		}

		internal void ReleaseContent()
		{
			mainPrintContentHolder.Content = null;
			_holders.ForEach(it => it.Content = null);
		}
	}
}
